#include "util/ByteTool.h"

void ByteTool::arraycopy(const uint8 *src,const int srcLength, int srcPos, uint8* dst, int dstLength,int dstPos, int length) {
    if (src == NULL) {
        return;
    }
    if (dst == NULL) {
        return;
    }
    if (srcPos < 0 || dstPos < 0 || length < 0 ||
        srcPos > srcLength - length || dstPos > dstLength - length) {
    	return;
    }
    // Copy byte by byte for shorter arrays.
    if (src == dst && srcPos < dstPos && dstPos < srcPos + length) {
        // Copy backward (to avoid overwriting elements before
        // they are copied in case of an overlap on the same
        // array.)
        for (int i = length - 1; i >= 0; --i) {
            dst[dstPos + i] = src[srcPos + i];
        }
    } else {
        // Copy forward.
        for (int i = 0; i < length; ++i) {
            dst[dstPos + i] = src[srcPos + i];
        }
    }
}


